import { type IObject, OType } from '@cscec/udp-ui';
import { useMemo } from 'react';

/**
 * 获取明细页面的初始化数据及业务主键
 */
export function useDetail({ masterTableName, detailTableMap }: any) {
  return useMemo(() => {
    const result: { initState: IObject; masterTableName: string } = {
      masterTableName,
      initState: {
        [masterTableName]: {},
      },
    };
    Object.keys(detailTableMap || {}).forEach((key) => {
      result.initState[detailTableMap[key]] = [];
    });
    return result;
  }, [masterTableName, detailTableMap]);
}

export function useDisabled(page: { oType: any; }) {
  const { oType } = page;
  return ![OType.Add, OType.Edit].includes(oType as OType);
}
